package request

import (
	"context"
	pb "demo_grpc/proto"
	"log"
	"strconv"

	"google.golang.org/grpc"
)

func RouteList(conn *grpc.ClientConn) {
	streamClient := pb.NewClientStreamClientClient(conn)
	//调用服务端RouteList方法，获流
	stream, err := streamClient.RouteList(context.Background())
	if err != nil {
		log.Fatalf("Upload list err: %v", err)
	}
	for n := 0; n < 10000; n++ {
		//向流中发送消息
		err := stream.Send(&pb.ClientStreamRequest{StreamData: "stream client rpc " + strconv.Itoa(n)})
		if err != nil {
			log.Fatalf("stream request err: %v", err)
		}
	}
	//关闭流并获取返回的消息
	res, err := stream.CloseAndRecv()
	if err != nil {
		log.Fatalf("RouteList get response err: %v", err)
	}
	log.Println(res)
}
